package com.cat.binaryTree02;

import java.util.ArrayDeque;
import java.util.Deque;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/LwUNpT/?envType=problem-list-v2&envId=xhsq2On3
 * @create 2025/10/2 21:16
 * @since JDK17
 */

public class Solution01 {
    public int findBottomLeftValue(TreeNode root) {
        Deque<TreeNode> q = new ArrayDeque<>();
        q.add(root);
        int ans = 0;
        TreeNode node = null;
        while (!q.isEmpty()) {
            for (int i = 0, end = q.size(); i < end; i++) {
                node = q.poll();
                if (node.right != null) {
                    q.addLast(node.right);
                }
                if (node.left != null) {
                    q.addLast(node.left);
                }
            }
        }

        return node.val;
    }
}
